<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            a: 1,
            b: [1, 2, 3],
            c: {
                cc: "3",
                ccc: {
                    deep: "4"
                }
            }
        };

        function cloneDeep(obj) {
            // 根据obj是否是数组来生产空数组或者空对象
            let newObj = Array.isArray(obj) ? [] : {};
            // 检测obj的类型
            if (typeof (obj) === 'object') {
                // 循环obj
                for (key in obj) {
                    // newObj当前这一项为原obj这一项经过cloneDeep函数返回的结果
                    newObj[key] = cloneDeep(obj[key])
                }
            } else {
                // 如果obj不是引用类型，则直接返回
                return obj
            }
            // 返回newObj
            return newObj
        }
        // cloneDeep(['1','2','3'])
        let res = cloneDeep(obj);
        console.log(obj);
        res.c.ccc.deep = 5;
        console.log(res);
        const object1 = [];
        console.log(object1.__proto__);
        console.log(object1.hasOwnProperty('map'));
    </script>
</body>

</html>